package hdoj;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class BFSHdu1372 {

	//从一个点到一个点，knight(国际象棋，对应中国象棋的马)最少要走几步
	//knight一共能走8个方向
	private static final int[][] dir = {{-1, 2}, {1, 2}, {-1, -2}, {1, -2}, 
										{-2, 1}, {2, 1}, {-2, -1}, {2, -1}};
	
	
	private int rows = 8, columns = 8;
	
	private int startX, startY;
	
	private int endX, endY;
	
	private int minLength = 0;
	
	private boolean[][] visited = new boolean[rows][columns];
	
	public static void main(String[] args) {
		BFSHdu1372 object = new BFSHdu1372();
		object.getRes();
	}
	
	public void getRes(){
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()){
			minLength = 0;
			String start = scanner.next();
			startY = start.charAt(0) - 'a';
			startX = start.charAt(1) - '1';
			String end = scanner.next();
			endY = end.charAt(0) - 'a';
			endX = end.charAt(1) - '1';
			bfs();
			System.out.println("To get from " + start + " to " + end + " takes " + minLength + " knight moves.");
		}
		scanner.close();
	}
	
	private class Node{
		int x; int y;
		int step;
		public Node(int x, int y){
			this.x = x;
			this.y = y;
		}
	}
	
	//Runtime: 452MS
	public void bfs(){
		Node temp = new Node(startX, startY);
		Queue<Node> queue = new LinkedList<>();
		queue.add(temp);
		for(int i = 0; i < rows; i++){
			Arrays.fill(visited[i], false);
		}
		visited[startX][startY] = true;
		while(!queue.isEmpty()){
			temp = queue.poll();
			if(temp.x == endX && temp.y == endY){
				minLength = temp.step;
				return;
			}
			for(int i = 0; i < dir.length; i++){
				int curX = temp.x + dir[i][0];
				int curY = temp.y + dir[i][1];
				if(curX < 0 || curX >= rows || curY < 0 || curY >= columns || visited[curX][curY]){
					continue;
				}
				Node next = new Node(curX, curY);
				next.step = temp.step + 1;
				visited[curX][curY] = true;
				queue.add(next);
			}
		}
	}
}
